/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1644289387089_7321';

  // add your middleware config here, 注意要采用驼峰式的写法
  config.middleware = ['errorHandler', 'auth'];

  // auth中间件的配置，除了注册、登录接口外，其他接口都需要使用该中间件
  config.auth = {
    match: ['/logout', '/user/follow', '/user/unfollow'
      , '/user/follows/', '/user/fans/', '/user/fan_drop'
      , '/user/statistics', '/user/followed'
      , '/video', '/video/', '/video_list/', '/video_read_auth/'
      , '/video_detail', '/video_detail/', '/video_detail/destroy'
      , '/fava', '/unfava', '/comment', '/vod/sign']
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  config.security = {
    // 关闭 csrf
    csrf: {
      enable: false,
    },
    // 跨域白名单
    // domainWhiteList: ['http://localhost:7001'],
  };
  // 允许跨域的方法
  config.cors = {
    origin: '*',
    allowMethods: 'GET, PUT, POST, DELETE, PATCH'
  };

  // 数据库配置
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    username: 'root',
    password: '11111111',
    port: 3306,
    database: 'egg-video',
    // 中国时区
    timezone: '+08:00',
    define: {
      // 取消数据表名复数
      freezeTableName: true,
      // 自动写入时间戳 created_at updated_at
      timestamps: true,
      // 字段生成软删除时间戳 deleted_at
      // paranoid: true,
      createdAt: 'created_time',
      updatedAt: 'updated_time',
      // deletedAt: 'deleted_at',
      // 所有驼峰命名格式化
      underscored: true,
    }
  };

  // 参数验证
  config.valparams = {
    locale: 'zh-cn',
    // 是否出现错误后直接抛出error
    throwError: true
  };

  // 加密
  config.crypto = {
    // 密钥可以自定义
    secret: '1qaz@4321_0987'
  };

  // jwt token
  config.jwt = {
    // 密钥可以自定义
    secret: "1qaz@4321_0987"
  };

  // redis
  config.redis = {
    client: {
      port: 6379,          // Redis port
      host: '127.0.0.1',   // Redis host
      password: '',        // 密码 默认为空
      db: 0,               // 选择第几个数据库
    }
  };

  config.multipart = {
    fileSize: '50mb',
    mode: 'stream',
    fileExtensions: ['.xls', '.txt', '.jpg', '.JPG', '.png', '.PNG', '.gif', '.GIF', '.jpeg', '.JPEG']
  };

  // 改成你自己的！！！注意端口
  config.webUrl = "127.0.0.1:7001";

  config.tencentVod = {
    secret_id: 'AKIDb1ANJzNUKuDF0TkkSt4ybx3rOegRv83m',
    secret_key: 'UgbFcjZ8QRBernRoujHYYHjSu53j8H9k',
    vodSubAppId: 1300165652
  };

  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.tpl': 'nunjucks',
    },
  };

  return {
    ...config,
    ...userConfig,
  };
};
